package com.bicon.botu.core.domain.entity;

import com.bicon.botu.core.base.common.utils.IdGen;

import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.util.Date;

/**
 * 数据库表实体的基类，继承了领域实体的基类
 * @param <T>
 */
@MappedSuperclass
public abstract class RepositoryEntity<T> extends BaseEntity{

    /**
     * 正常状态
     */
    public static final String LOGIC_DELETE_NORMAL = "0";
    /**
     * 逻辑删除状态
     */
    public static final String LOGIC_DELETE_TRUE = "1";


    @Id
    protected String id;

    protected Date createDate;	// 创建日期

    protected Date updateDate;	// 更新日期


    protected String logicDelete=LOGIC_DELETE_NORMAL; 	// 删除标记（0：正常；1：删除）

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public String getLogicDelete() {
        return logicDelete;
    }

    public void setLogicDelete(String logicDelete) {
        this.logicDelete = logicDelete;
    }

    public void preInsert(){
        if (id==null||id.equals("")){
            setId(IdGen.uuid());
        }
        this.updateDate = new Date();
        this.createDate = this.updateDate;
    }

    public void preUpdate(){
        this.updateDate = new Date();
    }
}